# -*- coding: utf-8 -*-

# -------------------------------
# Author    : linlingwei
# Email     : 951035650@qq.com
# File Name : twoCurve_rig.py
# Date      : 2019/10/17 
# IDE       : PyCharm
# Version   : 1.0.1
# -------------------------------

import maya.cmds as mc
import maya.mel as mel

import configs.constants.facial_constant as fc
import configs.constants.global_constant as gc
import configs.constants.suffix_constant as sc
import configs.constants.nodeType_constant as ntc
import configs.constants.attribute_constant as ac
reload(ac)

import scripts.commonCmds as con

class TwoCurve(object):
    
    def __init__(self,lname="test"):
        self.lname=lname
        pass
    
    def create(self,orgCrv,tgtCrv,number):
        name=self.lname
        lname = con.lname(name,"TC")
        lgrp = mc.createNode(ntc.tTransform,name = con.lname(lname,sc.sGrp))
        mc.addAttr(lgrp, ln=ac.global_scale, at="float", k=True, dv=1, min=0.00001)
        lstatic = mc.createNode(ntc.tTransform,name = con.lname(lname,sc.sStatic),parent=lgrp)
        mc.addAttr(lstatic,ln=ac.global_scale,at="float",dv=1,k=True)
        
        _orgCrv = mc.rename(orgCrv,con.lname(lname,"org",sc.sCrv))
        _tgtCrv = mc.rename(tgtCrv,con.lname(lname,"tgt",sc.sCrv))
        orgCrvShape = con.findRelatedShape(_orgCrv)
        tgtCrvShape = con.findRelatedShape(_tgtCrv)
        
        pro = 1./(number-1)
        for i in range(number):
    
            jot = mc.createNode(ntc.tJoint, name=con.lname(lname, i + 1, sc.sJot))
            mc.addAttr(jot, ln=ac.parameter, at="float", dv=i * pro, k=True)
            mc.setAttr(con.lAttr(jot, ac.parameter), l=True)
            
            org_poci = mc.createNode(ntc.tPointOnCurveInfo,name=con.lname(lname,"org",i+1,sc.sPoci))
            mc.connectAttr(orgCrvShape+".ws",org_poci+".ic")
            tgt_poci = mc.createNode(ntc.tPointOnCurveInfo, name=con.lname(lname, "tgt", i+1, sc.sPoci))
            mc.connectAttr(tgtCrvShape+".ws",tgt_poci+".ic")
            for poci in [org_poci,tgt_poci]:
                mc.setAttr(poci+".top",1)
                mc.connectAttr(con.lAttr(jot,ac.parameter),poci+".pr")
                # mc.setAttr(poci+".pr",i*pro)

            mc.parent(jot,lstatic)
            grp = con.emptyGroup(jot,["Zero"])[0]
            mc.connectAttr(org_poci+".p",grp+".t")
            mc.connectAttr(con.lAttr(lstatic,ac.global_scale),grp+".sx")
            mc.connectAttr(con.lAttr(lstatic,ac.global_scale),grp+".sy")
            mc.connectAttr(con.lAttr(lstatic,ac.global_scale),grp+".sz")

            tgt_trans = mc.createNode(ntc.tTransform,name= con.lname(lname,i+1,"trans"))
            mc.parent(tgt_trans,lstatic)
            mc.connectAttr(tgt_poci+".p",tgt_trans+".t")
            #tangentConstraint -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "object" -worldUpObject locator1;
            mc.tangentConstraint(_orgCrv,grp,worldUpObject=tgt_trans,aimVector=[1,0,0],upVector=[0,1,0],worldUpType="object",w=1)
            
        return
    

if __name__ == '__main__':
    pass